package codeblock;

public class CodeBlock01 {
    public static void main(String[] args) {
        Movie movie = new Movie("你好，李焕英");
        System.out.println("================================");
        Movie movie1 = new Movie("唐探3", 30, "小陈");

    }
}
class Movie {
    private String name;
    private double price;
    private String director;

    //3个构造器-->重载
    //(1)下面的三个构造器都有相同的语句
    //   这样代码看起来比较冗余
    //(2)这时可以把相同的语句，放到一个代码块中，即可
    //(3)这样当我们不管调用哪个构造器，创建对象，都会先调用代码块中的内容
    //(4)代码块调用的顺序优先于构造器
    {
        System.out.println("电影屏幕打开...");
        System.out.println("广告开始...");
        System.out.println("电影正式开始...");
    };

    public Movie(String name) {
        System.out.println("构造器 Movie(String name) 被调用");
        this.name = name;
    }

    public Movie(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public Movie(String name, double price, String director) {
        this.name = name;
        this.price = price;
        this.director = director;
    }
}
